<?php

use Biz\model\salesRebate\SalesPersonal as mSalesPersonal;
use Biz\service\salesRebate\SalesRebate as sSalesRebate;
use Doraemon\tools\ActionLog;
use Doraemon\tools\HhzClient;

class GetAccountAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    public function main()
    {
        $uid = $this->uid;
        //查看个人或者公司账户详情
        $type = $this->getRequest()->getPost('type', '');
        if (in_array(HhzClient::getClientType(), [HhzClient::APPTYPE_IOS, HhzClient::APPTYPE_ANDROID])) {
            $result['list'] = sSalesRebate::getAppSaleAccount($uid);
        } else {
            $result['list'] = sSalesRebate::getAccount($uid, $type, ['status[!]' => 9]);

            //查看当前申请单
            $code = $this->getRequest()->getPost('code', '');
            if ($code <> '') {
                $result['list']['apply'] = sSalesRebate::getOneApply(['withdrawal_code' => $code]);
            }

            //增加用户白名单
            $result['list']['user_list'] = array_keys(mSalesPersonal::USER_LIST);
        }

        ActionLog::log($this->uid, [
            'params' => json_encode($result, true),
        ], ActionLog::BIZ_SALES_REBATE);

        $this->setSuccess($result);
    }
}